#include "Util.hpp"
#include "db_Menage.hpp"
#include "httpserver.hpp"
#include <vector>

using std::string;
using std::vector;

#define FILEPATH "./www/index.html"

void FileUtilDemo()
{
    vod::FileUtil fu(FILEPATH);
    fu.CreateDirectory("./www/");
    fu.WriteFileData("<html></html>");
    std::string buffer;
    fu.ReadFileData(&buffer);
    std::cout << buffer << std::endl;
    std::cout << buffer.size() << std::endl;
}

void JsonUtil()
{
    string name("张三");
    int age = 20;
    vector<double> score{78.5, 56.5, 74.5};

    Json::Value js;
    js["name"] = name.c_str();
    js["age"] = age;
    for (auto &val : score)
        js["score"].append(val);

    // 序列化
    string SerData;
    vod::JsonUtil::Serialize(js, &SerData);
    std::cout << SerData << std::endl;

    // 反序列化
    Json::Value root;
    vod::JsonUtil::Deserialize(SerData, &root);
    int size = root["score"].size();
    for (int i = 0; i < size; ++i)
        std::cout << "name: " << root["name"].asString() << "  age: " << root["age"].asInt()
                  << "  score: " << root["score"][i].asDouble() << std::endl;
}

void DB_Menage_Demo()
{
    vod::TableVideo tv;
    Json::Value root;
    // root["name"] = "demo video";
    // root["info"] = "demo demo demo";
    // root["video"] = "/video/demo.mp4";
    // root["image"] = "/image/demo.jpg";

    // root["name"] = "小视频";
    // root["info"] = "懂得都懂!!!";
    // tv.Update(5, root);
    // tv.Insert(root);

    //tv.Delete(5);

    tv.SelectLike("demo", &root);
    vod::JsonUtil ju;
    std::string data;
    ju.Serialize(root, &data);
    std::cout << data << std::endl;
}

int main()
{
    vod::Server s(8080);
    s.RunServer();
    return 0;
}